package com.txm.service;

import java.util.HashMap;
/**
* 没有实际的用处，（解释：一个进程只会产生一个客户端socket线程，不会产生多个）
* */
public class ManageServerThreads {
    private static HashMap<String, Thread> mcts = new HashMap<>();

    public static HashMap<String, Thread> getMcts() {
        return mcts;
    }

    public Thread getMctsByKey(String key) {
        return mcts.get(key);
    }

    public static void addMctsByKey(String key, Thread thread) {
        ClientConnectServerThread thread_ = null;
//        System.out.println(mcts.get(key));
        if ((thread_ = (ClientConnectServerThread) mcts.get(key)) != null) {
            thread_.islive = false;
            mcts.remove(key);
            System.exit(1);
        }
        mcts.put(key, thread);
//        System.out.println("mctc:"+mcts);
    }

    public static Thread removeMctsByKey(String key) {
        Thread thread = mcts.get(key);
        mcts.remove(key);
        return thread;
    }
}
